// import request from '../utils/request';

import axios from 'axios';
import QS from 'qs';

/**
 * 动态切换头部地址
 * 以/api开头的进行反向代理
 */
axios.defaults.baseURL = process.env.NODE_ENV === "production" ? "http://ydsp.jsgl.cn:8296" : "/api";


const urls = {

    // 页面基础数据
    getAllUsers     : "/beadHouse/getUserByParam?",                                     // 获取全部用户信息
    getAllNurses    : "/beadHouse/getByParam?",                                         // 获取全部护工信息
    getAllOlders    : "/beadHouse/getOldersByParam?",                                   // 获取全部老人信息

    // 登录页面
    login           : "/beadHouse/login",                                               // 用户登陆

    // 用户管理
    updateUser      : "/beadHouse/updateOrAddUser",                                     // 新增/修改用户信息
    deleteUser      : "/beadHouse/deleteUsers",                                         // 删除用户信息
    getUsers        : "/beadHouse/getUsers?",                                           // 获取用户列表
    findById        : "/beadHouse/findById?",                                           // 根据Id获取用户信息
    getReleation    : "/beadHouse/selectReleation?",                                    // 获取用户信息 用户首页展示

    // 老人管理
    getOlders       : "/beadHouse/getOlders?",                                          // 获取老人列表
    updateOlder     : "/beadHouse/updateOrAddOlder",                                    // 新增/修改老人信息
    deleteOlder     : "/beadHouse/deleteOlders",                                        // 删除老人信息

    // 护工管理
    getNurses       : "/beadHouse/getNurses?",                                          // 获取护工列表
    updateNurse     : "/beadHouse/updateOrAddNurse",                                    // 新增/修改护工信息
    deleteNurse     : "/beadHouse/deleteNurses",                                        // 删除护工信息

    // 房间管理
    getRooms        : "/beadHouse/getRooms?",                                           // 获取房间列表
    updateRooms     : "/beadHouse/updateOrAddRooms",                                    // 新增/修改房间信息
    deleteRoom      : "/beadHouse/deleteRooms",                                         // 删除房间信息

    // 消息管理
    getNotices      : "/beadHouse/getNotices?",                                         // 获取消息列表



};


let getAllUsers = function(data) {
    return axios.get(urls.getAllUsers + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let getAllNurses = function(data) {
    return axios.get(urls.getAllNurses + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let getAllOlders = function(data) {
    return axios.get(urls.getAllOlders + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let login = function(data) {
    return axios.post(urls.login, data).then(({ statusText, data }) => {return data;});
};

let updateUser = function(data) {
    return axios.post(urls.updateUser, data).then(({ statusText, data }) => {return data;});
};

let deleteUser = function(data) {
    return axios.post(urls.deleteUser, data).then(({ statusText, data }) => {return data;});
};

let getUsers = function(data) {
    return axios.get(urls.getUsers + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let findById = function(data) {
    return axios.get(urls.findById + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let getReleation = function(data) {
    return axios.get(urls.getReleation + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let getOlders = function(data) {
    return axios.get(urls.getOlders + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let updateOlder = function(data) {
    return axios.post(urls.updateOlder, data).then(({ statusText, data }) => {return data;});
};

let deleteOlder = function(data) {
    return axios.post(urls.deleteOlder, data).then(({ statusText, data }) => {return data;});
};

let getNurses = function(data) {
    return axios.get(urls.getNurses + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let updateNurse = function(data) {
    return axios.post(urls.updateNurse, data).then(({ statusText, data }) => {return data;});
};

let deleteNurse = function(data) {
    return axios.post(urls.deleteNurse, data).then(({ statusText, data }) => {return data;});
};

let getRooms = function(data) {
    return axios.get(urls.getRooms + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

let updateRooms = function(data) {
    return axios.post(urls.updateRooms, data).then(({ statusText, data }) => {return data;});
};

let deleteRoom = function(data) {
    return axios.post(urls.deleteRoom, data).then(({ statusText, data }) => {return data;});
};

let getNotices = function(data) {
    return axios.get(urls.getNotices + QS.stringify(data)).then(({ statusText, data }) => {return data;});
};

export default {
    getAllUsers,
    getAllNurses,
    getAllOlders,
    login,
    updateUser,
    deleteUser,
    getUsers,
    findById,
    getReleation,
    getOlders,
    updateOlder,
    deleteOlder,
    getNurses,
    updateNurse,
    deleteNurse,
    getRooms,
    updateRooms,
    deleteRoom,
    getNotices,
};